package cn.org.mrliu.code.generator;

import java.sql.ResultSet;
import java.util.List;

import org.junit.Test;

import cn.org.mrliu.code.generator.bean.Column;
import cn.org.mrliu.code.generator.bean.Table;
import cn.org.mrliu.code.generator.dao.DBOperation;
import cn.org.mrliu.code.generator.dao.DBUtil;
import cn.org.mrliu.code.generator.dao.ResultSetHandler;
import cn.org.mrliu.code.generator.handler.TableHandler;

public class TestDBOperation {
	@Test
	public void testTable() {
		Table table = DBOperation.getTable("tb_customer");
		System.out.println(table);
	}

	@Test
	public void testColumns() {
		List<Column> columns = DBOperation.getColumns("tb_customer");
		System.out.println(columns);
	}

	@Test
	public void testTableService() {
		Table table = TableHandler.getTable("tb_customer");
		System.out.println(table);
	}

	@Test
	public void testJdbcUtilQuery() {
		String sql = "select TABLE_COMMENT from information_schema. TABLES where TABLE_SCHEMA = ? and table_name = ?";
		final String tableName = "tb_customer";
		Table table = DBUtil.query(sql, new ResultSetHandler<Table>() {
			@Override
			public Table handle(ResultSet rs) throws Exception {
				if (rs.next()) {
					return new Table(tableName, rs.getString("TABLE_COMMENT"));
				}
				return null;
			}
		}, "ssm", tableName);
		System.out.println(table);
	}
}
